<%@ page language="java" contentType="text/html;charset=utf-8"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
	<link rel="stylesheet" type="text/css" href="<%=path%>/css/button.css">
	<script type="text/javascript" src="<%=path%>/js/ajaxupload.js"></script>
</head>
<body>
	<%@include file="header.jsp" %>
	
	<div id="container">
		<div id="main" class="fullscreen">
			<div class="content fl person">
				<div class="section panel-box hijackthis hijacked">
					<div class="blog-article-box">
						<div style="margin-top:5px; margin-left: 50px;">
							<font color="red">请选择要上传的Excel文件(*.xsl)：</font>
							<input type="text" id="show" disabled='disabled' style="width: 200px;"/>
							<input type="button" id="select" value="选择上传文件" />
							<input type="button" id="submit" value="确定" />
							<font id="upload_msg" color="red"></font>
						</div>
					</div>
				</div>
			</div>
			<div class="content fl person">
				<div class="section panel-box hijackthis hijacked">
					<div class="blog-article-box">
						<div style="margin-top:5px;">
							<font style="font-weight: bold;">文件信息:</font>
							<div style="padding-left:50px;">
								<ul style="list-style-type:none">
									<li><font style="text-align: left">文件名：</font></li>
									<li><font style="text-align: left">文件大小：</font></li>
								</ul>
							</div>
							<hr/>
							
							<font style="font-weight: bold;">操作日志:</font>
<!-- 							<font style="float: right"><a style="text-decoration: 1px;">下载日志文件</a></font> -->
							<div style="padding-left:50px;" id="logsDiv">
								暂无操作日志......<br/>
							</div>
						</div>
					</div>
				</div>
			</div>
			
		</div>
	</div>
	<script type="text/javascript">
		var id ;   
		$(function() {
			var button = jQuery('#select');
			var load = new AjaxUpload(button, {//绑定AjaxUpload
				action: '<%=path%>/UploadFile_uploadFileByStruts2',
				type : "POST",
				data : {//还可以提交的值
					module : "ajaxupload"
				},
				autoSubmit : false,//选择文件后,是否自动提交.
				name : 'msUploadFile',//提交的名字
				onChange : function(file, ext) {//当选择文件后执行的方法,ext存在文件后续,可以在这里判断文件格式
					$("#show").attr("value", file);
 					$("#upload_msg").text("");
 					$("#logsDiv").text("暂无操作日志......");
				},
				onSubmit : function(file, ext) {//提交文件时执行的方法
					this.setData({fileName : $("#show").val()});
					$("#upload_msg").text(" 温馨提示：文件正在上传中...");
					this.disable();
				},
				onComplete : function(file, response) {//文件提交完成后可执行的方法
 					if(response == ""){
	 					$("#show").val("");
	 					$("#upload_msg").text("温馨提示：文件上传成功, 正在处理中...");
	 					$("#logsDiv").text("温馨提示：正在处理上传数据, 请等待......");
	 					handler(file);
 					}else{
 						alert("上传失败！请重试..." + response);
	 					$("#upload_msg").text(" 温馨提示：上传失败！请重试...");
 					}
	 				this.enable();
				}
			});
			var submit = jQuery('#submit').click(function() {
				load.submit();
				id = "requestLogs";
				$(document).everyTime(3000,id,loadmessage);
			});
		});
		
		
		function handler(filename){
			$.post("<%=path%>/Handler_exec",
					{"filename": filename},
			        function(data, textStatus){
				  		if(data.flag){
				  		//	alert("处理完毕!" );
				  		}
					},"json");
		}
	</script>
	<script type="text/javascript">
	    function loadmessage() {  
	    	$.post("<%=path%>/Handler_getHandlerLogs",
			        function(data, textStatus){
						if(data.over == "true"){
							$(document).stopTime(id);
						}
				  		$("#logsDiv").html(data.logs);
					}, "json");
	    }  
	</script>
</body>
</html>